<template>
  <div class="container">
    <van-nav-bar
      left-text="取消"
      right-text="完成"
      @click-left="$emit('close')"
      @click-right="upload"
    />
    <van-field
      v-model="localDate"
      rows="2"
      autosize
      type="textarea"
      maxlength="7"
      placeholder="请输入留言"
      show-word-limit
    />
  </div>
</template>

<script>
import { setUserProfile } from '@/api/user'
export default {
  methods: {
    async  upload () {
      this.$toast.loading({
        message: '修改中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await setUserProfile({ name: this.localDate })
        this.$emit('input', this.localDate)
        this.$toast.success('修改成功')
      } catch (err) {
        this.$toast.fail('修改失败')
      }
      this.$emit('close')
    }
  },
  data () {
    return {
      localDate: this.value
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  }
}
</script>

<style lang="less" scoped>
.van-nav-bar {
  background: #ffffff !important;
}
.container {
  background: rgb(250, 250, 250);
  height: 100%;
}
</style>
